/*
 * Yabumi, a 2d scrolling shoot-em-up game.
 * Copyright (C) 2003 Gemma Teruaki <terugen@yabumi.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 */

#include "../taskmanager.h"
#include "../sprite.h"
#include "../video.h"
#include "../util.h"
#include "explosion.h"

_list_header explosion_list_header;

void Explosion_Init()
{
  Create_list(&explosion_list_header);
}

void Explosion_Free()
{
  Free_list(&explosion_list_header);
}

_Explosion *Explosion_Create(int x, int y)
{
  _list_item *list_item;
  list_item = (_list_item *)pmalloc(sizeof(_list_item));
  Add_item_last(&explosion_list_header, list_item);
  _Explosion *explosion = &list_item->data.Explosion;
  explosion->root = list_item;

  explosion->x = x;
  explosion->y = y;
  return explosion;
}

task Explosion_Draw(_option *optv)
{
  _Explosion *explosion;
  explosion = (_Explosion *)optv->socket[0];

  int i;
  SDL_Surface *image;
  i = (optv->count / 3) % 4;
  image = Sprite_Explosion[i];
  Sprite_Add(explosion->x, explosion->y, Z_ORDER_D2, image);
  if (optv->count == ONETIME_COUNT) {
    Task_Add(Explosion_Kill, explosion, NULL, ONETIME_COUNT);
    return;
  };
}

task Explosion_Kill(_option *optv)
{
  _Explosion *explosion;
  explosion = (_Explosion *)optv->socket[0];

  if (optv->count == ONETIME_COUNT) {
    Kill_item(&explosion_list_header, (_list_item *)explosion->root);
    pfree(explosion->root);
  };
}

